#include <iostream>


int is7Pair(char card[34])
{
	int pair = 0;
	for(char i=0; i<34; i++)
	{
		if(card[i] && card[i] != 2 && card[i] != 4)//没有2,4张牌的肯定不是7对子牌型
			return 0;
		if(card[i] == 2)
			pair++;
		else if(card[i] == 4)
			pair += 2;
	}	
	return pair;
}
int getCardCount(char card[34])
{
	int sum = 0;
	for(int i=0; i<34; i++)
	{
		sum += card[i];
	}
	return sum;
}

bool checkHu(char card[34])
{	

	//拷贝下，参数不能重复使用
	char cardData[34];
	bcopy(card, cardData, sizeof(cardData));

	//7对子或则单调
	if(is7Pair(cardData) == 7 || is7Pair(cardData) == 1)
		return true;			

	char m_tmpcard[34];
	//下面判断是否胡牌
	//先判断将牌	
	for(char i=0; i<34;)
	{
		bcopy(cardData, m_tmpcard, sizeof(cardData));
		if(m_tmpcard[i] >= 2)//如果有将牌可能
		{
			m_tmpcard[i] -= 2;//去掉将牌
			for(char j=0; j<34-2;)//这里减2防止数组越界
			{
				if(!m_tmpcard[j]) //没有,不能跳转，后面要处理风向
				{
				}
				else if(m_tmpcard[j] > 0 && m_tmpcard[j] <= 2)//有1,2张牌
				{
					if(m_tmpcard[j+1] > 0 && m_tmpcard[j+2] > 0) //能吃，减去
					{
						m_tmpcard[j] -= 1;
						m_tmpcard[j+1] -= 1;
						m_tmpcard[j+2] -= 1;
						continue;
					}
					else
					{
						break;
					}
				}
				else if(m_tmpcard[j] == 3) //刻
				{
					if(m_tmpcard[j+1] ==3 && m_tmpcard[j+2] == 3)//后面2个都是刻
					{
						m_tmpcard[j] = 0;
						m_tmpcard[j+1]  = 0;	
						m_tmpcard[j+2]  = 0;
					}
					else if(m_tmpcard[j+1] < 3)
					{
						m_tmpcard[j] = 0;
					}	
					m_tmpcard[j] = 0;
				}
				else if(m_tmpcard[j] == 4)//杠
				{
					if(m_tmpcard[j+1] >0 && m_tmpcard[j+2] >0 )//杠的话不用算前面2个，因为先吃过了
					{
						m_tmpcard[j] = 0;//杠的话自己刻一个，加后面组合
						m_tmpcard[j+1]  -= 1;
						m_tmpcard[j+2]  -= 1;
					}
					else 
						break;
				}

				if(j%9 == 6) //判断是否到7W，7筒，7条，后面无法吃，只能碰，要么做将头
				{
					if(m_tmpcard[j+1] && m_tmpcard[j+1] == 3)
					{
						m_tmpcard[j+1] = 0;
					}
					if(m_tmpcard[j+2] && m_tmpcard[j+2] == 3)
					{
						m_tmpcard[j+2] = 0;
					}	

				}
				if(j%9 == 6)
				{
					j += 3;//这边判断是否到7W，7筒，7条
					//这里处理风向
					if(j==27)
					{
						if(m_tmpcard[27] && m_tmpcard[27] == 3)
						{
							m_tmpcard[27] = 0;
						}
						if(m_tmpcard[28] && m_tmpcard[28] == 3)
						{
							m_tmpcard[28] = 0;
						}
						if(m_tmpcard[29] && m_tmpcard[29] == 3)
						{
							m_tmpcard[29] = 0;
						}
						if(m_tmpcard[30] && m_tmpcard[30] == 3)
						{
							m_tmpcard[30] = 0;
						}
						if(m_tmpcard[31] && m_tmpcard[31] == 3)
						{
							m_tmpcard[31] = 0;
						}
						if(m_tmpcard[32] && m_tmpcard[32] == 3)
						{
							m_tmpcard[32] = 0;
						}
						if(m_tmpcard[33] && m_tmpcard[33] == 3)
						{
							m_tmpcard[33] = 0;
						}


						break;
					}
				}
				else
					j++;
			}
		}

		//这里要判断是否完成
		if(getCardCount(m_tmpcard) == 0)
			break;
		i++;	
	}	

	if(getCardCount(m_tmpcard) == 0)
		return true;
	else 
		return false;
}
bool isXiaJiao()
{
//	char card[34] = {1,1,2,1,0,2,0,0,0,0,1,3,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
//	char card[34] = {0,0,1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
//	char card[34] = {0,0,0,0,1,0,0,0,0,2,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
//	char card[34] = {0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0};
	char card[34] = {0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,2,1,2,3,3,0,0,0,0,0,0,0,0,0,0};
	
	for(char i = 0; i < 34; i++)
	{
		card[i] += 1;
		if(checkHu(card))
		{
			return true;
		}
		card[i] -= 1;
	}

	return false;
}


int main()
{
	if(isXiaJiao())
	{
		std::cout<<"true!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
	}
	else
	{
		std::cout<<"false!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
	}
	return 0;
}
